#!/usr/bin/env bash

# Easier navigation: .., ..., ...., ....., ~ and -
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ~="cd ~" # `cd` is probably faster to type though
alias -- -="cd -"

alias findx="find . -name"
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias l='ls -CF --color=auto'
alias ls='ls --show-control-chars --sort=extension --color=auto'
alias ll='ls -alF --color=auto --time-style=long-iso'
alias la='ls -A --color=auto'
alias lh='ls -lh'
# List only directories
alias lsd="ls -lF --color=auto | grep --color=auto '^d'"
alias psg='ps -aux | grep'
alias grep='grep --color=auto -i'
alias fgrep='fgrep --color=auto -i'
alias egrep='egrep --color=auto -i'
alias reload='source ~/.bashrc'
alias tar-cgz='tar --use-compress-program=pigz -cpf'
alias tar-xgz='tar --use-compress-program=pigz -xpf'
alias tar-cxz='tar --use-compress-program="xz -T 0" -cpf'
alias tar-xxz='tar --use-compress-program="xz -T 0" -xpf'
alias cppstd='gcc -E -dM - < /dev/null | grep __STDC_VERSION__'
alias cver='strings /usr/lib/x86_64-linux-gnu/libc.so.6 | grep GLIBC_'
alias cppver='strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX_'
alias ln-py2='sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1'
alias ln-py3='sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2'
alias chose-py='sudo update-alternatives --config python'

# Print each PATH entry on a separate line
alias path='echo -e ${PATH//:/\\n}'

# Git Commands
alias ga='git add'
alias gapply='git am'
alias gb='git branch -v'
alias gba='git branch -a -v'
alias gbd='git branch -d'
alias gclone='git clone'
alias gclean='git clean -d -f'
alias gca='git commit --amend'
alias gcm='git commit -m'
alias gck='git checkout'
alias gcp='git cherry-pick'
alias gd='git d'
alias gdescribe='git describe --tags'
alias gdm='git dm'
alias gfc='git fc'
alias gfm='git fm'
alias gl='git l'
alias glt='git tag -l'
alias gm='git merge'
alias go='git go'
alias gpatch='git format-patch -M'
alias gpl='git pull --rebase'
alias gplo='git pull origin master'
alias gps='git push'
alias gpo='git push -u origin'
alias gpf='git push origin --force'
alias grh='git reset HEAD^'
alias gra='git rebase --abort'
alias grc='git rebase --continue'
alias gri='git rebase -i'
alias grao='git remote add origin'
alias grso='git remote show origin'
alias grmob='git push origin --delete'
alias grmot='git push origin --delete tag'
alias gs='git status'
alias gsh='git stash'
alias gshp='git stash pop'
alias gsub-init='git submodule update --init --recursive'
alias gub='git remote update origin -p'
alias gwho='git whoami'

# make commands
alias mall="make all"
alias mclean="make clean"
alias mconfig="make menuconfig"
alias mdistclean="make distclean"

# apt Commands
alias ainstall='sudo apt-get install'
alias asearch='sudo apt-cache search'
alias alist='sudo apt list --installed'
alias aremove='sudo apt-get remove'
alias aclean='sudo apt-get autoremove && sudo apt-get autoclean'
alias apurge='sudo apt-get purge'
alias aupdate='sudo apt-get update'
alias aupgrade='sudo apt-get upgrade'

# dpkg Commands
alias list-pkg='sudo dpkg -l'
alias cat-pkg-files='sudo dpkg -L'

# systemd Commands
alias cat-service='sudo systemctl list-units --type=service'
alias cat-target='sudo systemctl list-units --type=target'
alias service-enable='sudo systemctl enable'
alias service-disable='sudo systemctl disable'
alias service-start='sudo systemctl start'
alias service-stop='sudo systemctl stop'
alias service-status='sudo systemctl status'
alias service-restart='sudo systemctl restart'
alias service-reload='sudo systemctl daemon-reload'
alias plot-service-start-order='sudo systemd-analyze plot > start_order.svg'

# journalctl Commands
alias log-sync='sudo journalctl --sync'
alias log-clean='sudo journalctl --vacuum-size=1'
alias log-status='sudo systemctl status systemd-journald'
alias cat-systemd-log='sudo journalctl --system'
alias cat-kernel-log='sudo journalctl -k'
alias cat-unit-log='sudo journalctl -u'
alias cat-xxx-log='sudo journalctl -t'

# pre-commit Commands
alias pre-commit-install='pre-commit install -c ~/.pre-commit-config.yaml;
                          gitlint -C ~/.gitlint install-hook'
alias pre-commit-uninstall='pre-commit uninstall -c ~/.pre-commit-config.yaml;
                            gitlint -C ~/.gitlint uninstall-hook'
alias pre-commit-update='pre-commit autoupdate -c ~/.pre-commit-config.yaml --bleeding-edge'
alias pre-commit-clean='rm -rf ~/.cache/pre-commit/'
alias pre-commit-rmold='pre-commit uninstall; gitlint uninstall-hook;
                        rm .pre-commit-config.yaml init_pre_commit_hook.sh'

# new file
alias new-h='cp ~/template/h.h'
alias new-hpp='cp ~/template/h.hpp'
alias new-c='cp ~/template/c.c'
alias new-py='cp ~/template/py.py'
alias new-mk='cp ~/template/mk.mk'
